<?php

// File : file_utilities.php

// Reads a text file and returns the contents as an array.
function read_lines($filename, $trim_whitespace = TRUE, $skip_blank_lines = TRUE)
{
    $filestring = file_get_contents($filename);
    
    $temp_array = explode("\n", $filestring);
    $line_array = array();
    $n = count($temp_array);
    
    for ($i = 0; $i < $n; $i++)
    {
        $line = $temp_array[$i];
        if ($trim_whitespace)
            $line = trim($line);
            
        if ($skip_blank_lines != TRUE || $line != "")
            $line_array[] = $line;
    }
    return $line_array;
}

function echo_file($filename)
{
    $line_array = read_lines($filename, FALSE, FALSE);
    $n = count($line_array);
    for ($i = 0; $i < $n; $i++)
    {
        echo $line_array[$i];
        echo "<br />";
    }
    echo "Read $n lines";
}

?>